<?php
//echo "<pre>";
//print_r($_FILES);
//error_reporting(1);


if(is_uploaded_file ($_FILES['avatar']['tmp_name'])){
#if(isset($_FILES['avatar']) && !empty($_FILES['avatar'])){
    if($_FILES['avatar']['error']==0) {
        if(is_uploaded_file ($_FILES['avatar']['tmp_name'])){
            $fileName = $_FILES['avatar']['name'];
            $fileName = date('ymdHis').'_'.uniqid().$fileName;
            $source = $_FILES['avatar']['tmp_name'];
            $dest = "uploads/$fileName";
            $flag =  move_uploaded_file($source, $dest);
            if($flag == true){
                echo "<h4>WOW !! Success !!!!</h4>";
            } else {
                echo "<h4>Your Bad !!</h4>";
            }
        }
    } else
    if($_FILES['avatar']['error']==1) {
        echo "File Size exceed 2MB";
    } else if($_FILES['avatar']['error']==4) {
        echo "Please upload file";
    }

}

echo "</pre>";
?>
<!--------- UPLOAD FORM START --->
<form name="upload-form"
    action="" method="post"
    enctype="multipart/form-data" >
<input type="file" name="avatar">

<input type="submit" name="upload" value="I am done!!">
</form>
<!-------------------->
